<template>
  <div>
    <div>
      <FilterTable
        ref="table"
        height="210"
        columnsRef="partAccessAccessInventoryTabsSelect"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'rows'"
        :onColumnsChange="columns => (this.columns = columns)"
        :onRowSelectChange="saveData"
      >
      </FilterTable>
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">取 消</el-button>
      <el-button v-if="type !== 'show'" type="primary" @click="saveDialog">{{ type == 'add' ? '保存' : '编辑' }}</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { findAllInventoryInfo } from '@/api/part/access/accessInventory';
export default {
  name: 'select',
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'add'
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    this.conf = { add: '确定', edit: '保存' };
    this.saveTabData = null;
    return {
      arr: {},
      fetchApi: findAllInventoryInfo,
      fetchParams: {},
      columns: this.createFormList()
    };
  },
  computed: {
    btnText() {
      return this.conf[this.type];
    }
  },
  created() {
    this.init();
  },
  methods: {
    saveData(row) {
      this.arr = row;
      console.log(this.arr);
    },
    init() {
      if (this.type === 'edit') {
        // 更新接口需要的记录 ID
        this.recordId = this.rowData.brandId;
        this.formList.forEach(x => {
          x.initialValue = this.rowData[x.fieldName];
        });
      }
    },
    createFormList() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '盘点单号',
          dataIndex: 'inventoryNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '盘点日期',
          dataIndex: 'inventoryDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经手人',
          dataIndex: 'handler',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '操作员',
          dataIndex: 'handler1',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '锁定人',
          dataIndex: 'lockUser',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    errorFunction() {
      this.$notify.error({
        title: '错误',
        message: '请选择数据'
      });
    },
    async saveDialog() {
      if (this.arr.length > 0) {
        this.$emit('getData', false, this.arr);
      } else {
        this.errorFunction();
      }
    },
    closeDialog(param) {
      this.$emit('close', false, param);
    }
  }
};
</script>

<style lang="less" scoped></style>
